#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int arr[N][N];
int dp[N][N];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < n+1; i++)
	{
		for (int j = 1; j < n+1; j++) {
			cin >> arr[i][j];
		}
	}
	dp[1][1] = 0;
	for (int i = 1; i < n + 1; i++)
	{
		for (int j = 1; j < n + 1; j++)
		{
			if (i == 1 && j == 1)
			{
				continue;
			}
			else if (i == 1)
			{
				dp[i][j] = arr[i][j] + dp[i][j - 1];
			}
			else if (j == 1)
			{
				dp[i][j] = arr[i][j] + dp[i - 1][j];
			}
			else
			{
				dp[i][j] = arr[i][j] + min(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}